<?php
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2019/7/4 11:25
// +----------------------------------------------------------------------

namespace app\single\model;


use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\Model;

class BanModel extends Model
{
    public function initialize()
    {
        $this->table = config("database.game").".log_ban";
    }

    /**
     * 查询值是否存在
     * @param $type
     * @param $value
     * @return bool
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     */
    public function checkValue($type,$value): bool
    {
        $map["type"] = $type;
        $map["value"] = $value;
        $data = $this->where($map)->field("value")->find();
        if($data){
            return true;
        }
        return false;
    }

    /**
     * 插入数据
     * @param $type
     * @param $value
     * @return mixed
     */
    public function addValue($type,$value)
    {
        $data = array(
            "type" => $type,
            "value" => $value
        );
        return $this->insert($data);
    }

    /**
     * 删除数据
     * @param $type
     * @param $value
     * @return mixed
     * @throws Exception
     * @throws PDOException
     */
    public function deleteValue($type,$value)
    {
        $map["type"] = $type;
        $map["value"] = $value;
        return $this->where($map)->delete();
    }
}